package cn.hrlly.tao2shou.biz;

import android.content.Context;

import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.AlterUserInfoCallback;
import cn.hrlly.tao2shou.domain.User;
import cn.hrlly.tao2shou.listener.OnAlterUserInfoListener;
import cn.hrlly.tao2shou.utils.DatabaseUtil;

/**
 * User: gengliang
 * Date: 2016-01-31
 * Time: 19:30
 */

public class AlterUserInfoBizImpl implements AlterUserInfoBiz {

    private OnAlterUserInfoListener onAlterUserInfoListener;
    private DatabaseUtil databaseUtil;

    public AlterUserInfoBizImpl(OnAlterUserInfoListener onAlterUserInfoListener,Context context) {
        this.onAlterUserInfoListener = onAlterUserInfoListener;
        this.databaseUtil=new DatabaseUtil(context);
    }

    @Override
    public void alterUserInfo(User user, File file) {
        OkHttpUtils
                .postFile()
                .url(Config.key_url)
                .file(file)
                .addParams(Config.key_action, Config.action_alter_user_info)
                .addParams(Config.key_nickname,user.getNickname())
                .addParams(Config.key_gender,user.getGender())
                .addParams(Config.key_school,user.getSchool())
                .build()
                .execute(new AlterUserInfoCallback(onAlterUserInfoListener));
    }

    @Override
    public void saveUserInfo(User user) {
        databaseUtil.updateUserInfo(user);
    }

    @Override
    public void closeDataBase() {
        databaseUtil.closeDatabase();
    }
}
